import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        //用户信息
        userInfo:{
            success: false,
            role: '',
            nickName: '',
            roleName: '',
            userArea: '',
        },
        //页面跳转信息状态管理
        jumpPage:{
            //存储中文的页面跳转标题
            title:'',
            //存储英文的页面跳转标题参数，准备之后post给后端的参数
            titleRes:''
        },
        //管控页面宫格固定数据
        chartsItem:[{
            id: '1',
            icon: "bar-chart-o",
            text: "发生频率",
            itemName: "happenChart"
        }, {
            id: '2',
            icon: "bar-chart-o",
            text: "能量波动",
            itemName: "energyChart"
        }, {
            id: '3',
            icon: "bar-chart-o",
            text: "破坏类型",
            itemName: "destroyChart"
        }, {
            id: '4',
            icon: "bar-chart-o",
            text: "严重程度",
            itemName: "damageChart"
        }, {
            id: '5',
            icon: "bar-chart-o",
            text: "图表拓展测试模块",
            itemName: "extraChart"
        }],
        tablesItem: [{
            id: "1",
            icon: "notes-o",
            text: "发生次数",
            itemName: "happenTable"
        }, {
            id: "2",
            icon: "notes-o",
            text: "能量监测",
            itemName: "energyTable"
        }, {
            id: "3",
            icon: "notes-o",
            text: "破坏类型",
            itemName: "destroyTable"
        }, {
            id: "4",
            icon: "notes-o",
            text: "严重程度",
            itemName: "damageTable"
        }, {
            id: "5",
            icon: "notes-o",
            text: "工况信息",
            itemName: "stationTable"
        },],
        monitorItem:[
            {
                id:'1',
                text:'严重事件',
                itemName:'seriousItem',
                num: 0
            },
            {
                id:'2',
                text:'警告事件',
                itemName:'usualItem',
                num: 0
            },
            {
                id:'3',
                text:'轻微事件',
                itemName:'seriousItem',
                num: 0
            }
        ],
        monitorRequestData:{
            time:'recentAllYear',
            area:'hysk'
        },
        //缺省值默认数据 起始时间 防止程序因空值崩溃
        initData:{
            start_time:'2020-06-01',
            end_time:'2021-07-13'
        },
        //公告数据状态管理
        bulletinsData:{
            tabActive: "a"
        },
        //科普模块数据
        popuScienceItem:[
            {
                id:1,
                text:"煤矿微震知识图谱",
                to:"/popuScience"
            },
            {
                id:2,
                text: "软件的系统设置",
                to:"/popuScience"
            },
            {
                id:3,
                text: "煤矿巷道三维建模的原理",
                to:"/popuScience"
            },
            {
                id:4,
                text: "震级与烈度",
                to:"/popuScience"
            },
            {
                id:5,
                text: "微震预警原理",
                to:"/popuScience"
            },
            {
                id:6,
                text: "微震预警的意义",
                to:"/popuScience"
            }

        ],
        //筛选条件参数
        sieveData:{
            startTime:'2020-01-01',
            endTime:'2021-07-30',
            //筛选时间（在台站工况中）
            stationTime:'',
            //筛选台站
            station:'',
            //筛选矿区
            sieveArea:''
        },
        //台站信息
        stationItemInfo:{
            hyStations:['R']
        }
    },
    getters: {
        //转换地区信息为中文形式
        userAreaInfo(state) {
            switch (state.userInfo.userArea) {
                case "hysk":
                    return '辽阳红阳三矿';
                    break;
                case "all":
                    return '辽宁大学监测小组';
                    break;
                case "none":
                    return '游客';
                    break;
                case "mdt":
                    return '山西马道头煤矿集团';
                    break;
                case "sys":
                    return '黑龙江集贤矿区';
                    break;
                case "pds":
                    return '河南平顶山十一矿';
                    break;
                case "dt":
                    return '山西塔山煤矿';
                    break;
                default:
                    break;
            }
        },
        //转换二级管理员为 user  格式，目的是管控页面需要一个总体的数值进行判断
        userRoleInfo(state){
            switch (state.userInfo.role){
                case "ROLE_hysk":
                    return "ROLE_user";
                    break;
                case "ROLE_mdt":
                    return "ROLE_user";
                    break;
                case "ROLE_sys":
                    return "ROLE_user";
                    break;
                case "ROLE_dt":
                    return "ROLE_user";
                    break;
                case "ROLE_pds":
                    return "ROLE_user";
                    break;
                case "ROLE_admin":
                    return "ROLE_admin";
                    break;
                case "ROLE_tour":
                    return "ROLE_tour";
                    break;
                default:
                    break;
            }
        },
        //根据area转换为数据库表名字段 for post
        userAreaSwitchTableName(state){
            const tbNamePrefix = "mine_quake_results_";
            if (state.userInfo.userArea){
                switch (state.userInfo.userArea) {
                    case "hysk":
                        return tbNamePrefix+'hongyang';
                        break;
                    //对于超级管理员应进行逻辑判断——通过所选择的矿区筛选器的值(初始为红阳三矿)
                    case "all":
                        return tbNamePrefix+'hongyang';
                        break;
                    case "mdt":
                        return tbNamePrefix+'hongyang';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "sys":
                        return tbNamePrefix+'hongyang';
                        break;
                    case "pds":
                        return tbNamePrefix+'pingdingshan';
                        break;
                        //无数据，默认使用 红阳三矿数据
                    case "dt":
                        return tbNamePrefix+'hongyang';
                        break;
                    default:
                        break;
                }
            }
        },
        //根据监控器筛选转换数据库表名
        monitorAreaSwitchTableName(state){
            const tbNamePrefix = "mine_quake_results_";
            if (state.monitorRequestData.area){
                switch (state.monitorRequestData.area) {
                    case "hysk":
                        return tbNamePrefix+'hongyang';
                        break;
                    case "mdt":
                        return tbNamePrefix+'hongyang';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "sys":
                        return tbNamePrefix+'hongyang';
                        break;
                    case "pds":
                        return tbNamePrefix+'pingdingshan';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "dt":
                        return tbNamePrefix+'hongyang';
                        break;
                    default:
                        break;
                }
            }
        },
        //根据监控器筛选转换cad组件链接
        monitorAreaSwitchCadCompo(state){
            const tbNamePrefix = "http://www.cdmw-lnu.cn/cad_html/";
            if (state.monitorRequestData.area){
                switch (state.monitorRequestData.area) {
                    case "hysk":
                        return tbNamePrefix+'hysk_cad.html';
                        break;
                    case "mdt":
                        return tbNamePrefix+'mdt.html';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "sys":
                        return tbNamePrefix+'sys_cad.html';
                        break;
                    case "pds":
                        return tbNamePrefix+'pds_cad.html';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "dt":
                        return tbNamePrefix+'dt_cad.html';
                        break;
                    default:
                        break;
                }
            }
        },
        //根据地名转换cad组件链接
        monitorAreaSwitchCadByUserArea(state){
            const tbNamePrefix = "http://www.cdmw-lnu.cn/cad_html/";
            if (state.userInfo.userArea){
                switch (state.userInfo.userArea) {
                    case "hysk":
                        return tbNamePrefix+'hysk_cad.html';
                        break;
                    case "mdt":
                        return tbNamePrefix+'mdt.html';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "sys":
                        return tbNamePrefix+'sys_cad.html';
                        break;
                    case "pds":
                        return tbNamePrefix+'pds_cad.html';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "dt":
                        return tbNamePrefix+'dt_cad.html';
                        break;
                    default:
                        break;
                }
            }
        },
        //适用于台站工况 根据area转换为数据库表名字段 for post
        userAreaSwitchTableNameForStations(state){
            const tbNamePrefix = "mine_quake_station_";
            if (state.userInfo.userArea){
                switch (state.userInfo.userArea) {
                    case "hysk":
                        return tbNamePrefix+'hongyang';
                        break;
                    //对于超级管理员应进行逻辑判断——通过所选择的矿区筛选器的值(初始为红阳三矿)
                    case "all":
                        return tbNamePrefix+'hongyang';
                        break;
                    case "mdt":
                        return tbNamePrefix+'pingdingshan';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "sys":
                        return tbNamePrefix+'hongyang';
                        break;
                    case "pds":
                        return tbNamePrefix+'pingdingshan';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "dt":
                        return tbNamePrefix+'hongyang';
                        break;
                    default:
                        break;
                }
            }
        },
        //根据筛选矿区名字切换微震结果集数据库表名
        sieveAreaSwitchTableName(state){
            const tbNamePrefix = "mine_quake_results_";
            if (state.sieveData.sieveArea){
                switch (state.sieveData.sieveArea) {
                    case "红阳三矿":
                        return tbNamePrefix+'hongyang';
                        break;
                    case "马道头":
                        return tbNamePrefix+'hongyang';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "双鸭山":
                        return tbNamePrefix+'hongyang';
                        break;
                    case "平顶山":
                        return tbNamePrefix+'pingdingshan';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "大同":
                        return tbNamePrefix+'hongyang';
                        break;
                    default:
                        break;
                }
            }
        },
        //根据筛选矿区名字切换台站结果集数据库表名
        sieveAreaSwitchStationTableName(state){
            const tbNamePrefix = "mine_quake_station_";
            if (state.sieveData.sieveArea){
                switch (state.sieveData.sieveArea) {
                    case "红阳三矿":
                        return tbNamePrefix+'hongyang';
                        break;
                    case "马道头":
                        return tbNamePrefix+'pingdingshan';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "双鸭山":
                        return tbNamePrefix+'hongyang';
                        break;
                    case "平顶山":
                        return tbNamePrefix+'pingdingshan';
                        break;
                    //无数据，默认使用 红阳三矿数据
                    case "大同":
                        return tbNamePrefix+'hongyang';
                        break;
                    default:
                        break;
                }
            }
        }
    },
    mutations: {
        changeStatus(state, userStatus) {
            state.userInfo.success = userStatus;
        },
        changeRole(state, userRole) {
            state.userInfo.role = userRole;
        },
        changeNickName(state, nickName) {
            state.userInfo.nickName = nickName;
        },
        changeRoleName(state, roleName) {
            state.userInfo.roleName = roleName;
        },
        changeUserArea(state, area) {
            state.userInfo.userArea = area;
        },
        //更改公告切换栏
        changeBulletinInfo(state,tabActive){
            state.bulletinsData.tabActive = tabActive;
        },
        //更改跳转页面英文字母信息
        changeJumpPageInfo(state,titleRes){
            state.jumpPage.titleRes = titleRes;
        },
        //更换跳转页面中文信息
        changeJumpPageChnInfo(state,title){
            state.jumpPage.title = title;
        },
        //更改监视器严重数量
        changeMonitorIndexNum(state,monitorNumList){
            state.monitorItem[0].num  = monitorNumList.seriousAlarm;
            state.monitorItem[1].num  = monitorNumList.usualAlarm;
            state.monitorItem[2].num  = monitorNumList.slightAlarm;
        },
        //更改监视器时间筛选
        changeMonitorTime(state,time){
            state.monitorRequestData.time = time;
        },
        //更改监视器矿区筛选
        changeMonitorArea(state,area){
            state.monitorRequestData.area = area;
        },
        //更改筛选时间条件方法
        changeSieveDataFunc(state,sieveInfo){
          state.sieveData.startTime = sieveInfo.startTime;
          state.sieveData.endTime = sieveInfo.endTime;
        },
        //更改筛选矿区条件
        changeSieveAreaFunc(state,sieveArea){
            state.sieveData.sieveArea = sieveArea;
        }
    },
    actions: {},
    modules: {}
})
